package com.lcq.gulimall.product.web;

import com.lcq.gulimall.product.entity.CategoryEntity;
import com.lcq.gulimall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class IndexController {
    @Autowired
    CategoryService categoryService;
    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
        List<CategoryEntity> categories = categoryService.getCategoriesByLevel(1);
        model.addAttribute("categories",categories);
        return "index";
    }

    @ResponseBody
    @GetMapping("index/catalog.json")
    public String getCatalogJson(){
        //Map map = categoryService.getCatalogJsonOp();
        String map = categoryService.getCatalogJsonRedis();
        return map;
    }

}
